package com.ityu.controller;


import com.ityu.anno.Log;
import com.ityu.pojo.Dept;
import com.ityu.pojo.result.Result;
import com.ityu.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    DeptService deptService;

    @GetMapping
    public Result listDept(){
        log.info("-----DeptController-----查询所有部门");
        return  Result.success( deptService.listDept() );
    }

    @Log
    @DeleteMapping
    public Result deleteDpet(Integer id){
        log.info("-----DeptController-----删除部门,参数为{}", id );
        deptService.deleteDept(id);
        return Result.success();
    }

    @Log
    @PostMapping
    public Result addDept(@RequestBody Dept dept ){
        log.info("-----DeptController-----添加部门,参数为{}",dept);
        deptService.addDept(dept);
        return Result.success();
    }



    @GetMapping("/{id}")
    public Result getDeptById( @PathVariable Integer id ){
        log.info("-----DeptController-----根据id查询部门，参数为{}",id);
        return Result.success( deptService.getDeptById(id) );
    }


    @Log
    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        log.info("-----DeptController-----更新部门,参数为{}",dept);
        deptService.updateDept(dept);
        return Result.success();
    }
}
